from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import JsonResponse


class LoginRequiredJsonMixin(LoginRequiredMixin):
    """
    需要登陆的界面，未登陆直接返回json格式错误.
    """
    def handle_no_permission(self):
        return JsonResponse({'code': 400, 'errmsg': '当前用户没有登陆'}, json_dumps_params={'ensure_ascii': False})